home *** CD-ROM | disk | FTP | other *** search
- //• --------------------------------------------------------------- •//
- //• A public domain demo of a "news flash" text splash screen, •//
- //• courtesy of Kenneth A. Long (kenlong@netcom.com). •//
- //• An itty bitty bytes™ production, for the benefit of anyone •//
- //• who wants use it. •//
-
- //• This is basically just "Bullseye" with some things dumped and •//
- //• one routine added, and a resource file to back the additions. •//
-
- //• The routine was from the old Pascal source - File v1.1, by •//
- //• Cary Clark, 13 May 1985, which I ported to C. The program •//
- //• was a simple text file opening/saving program. The about box •//
- //• was the only cool thing about the whole program. •//
-
- //• It's not the cleanest port in the world, but HEY! It works! •//
- //• I put a 3 tick delay in the scaling loop, to make the text •//
- //• arrival a little more viewable. The other 180 tick delay was •//
- //• originally 300 ticks. •//
-
- //• Enjoy! •//
-
- //• --------------------------------------------------------------- •//
-
- //• NewsSplash.c
-
- void InitMacintosh (void);
- void SetUpMenus (void);
- void HandleEvent (void);
- void HandleMouseDown (EventRecord *theEvent);
- void AdjustMenus (void);
- static void enable (MenuHandle menu, short item, short ok);
- void HandleMenu (long mSelect);
- void main (void);
- void NewAbout (void);
-
- #define aboutID 128
-
- MenuHandle appleMenu, fileMenu;
-
- enum {
- appleID = 1,
- fileID
- };
-
- enum {
- quitItem = 1
- };
-
- WindowPtr shell_window;
-
- void InitMacintosh(void)
- {
- MaxApplZone();
-
- InitGraf(&qd.thePort);
- InitFonts();
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- InitCursor();
-
- }
-
- void SetUpMenus (void)
- {
- InsertMenu (appleMenu = NewMenu (appleID, "\p\024"), 0);
- InsertMenu (fileMenu = NewMenu (fileID, "\pFile"), 0);
- DrawMenuBar ();
- AppendMenu (appleMenu, "\pAbout item");
- AddResMenu (appleMenu, 'DRVR');
- AppendMenu (fileMenu, "\pQuit/Q");
- }
-
- void HandleEvent(void)
- {
- int ok;
- EventRecord theEvent;
-
- HiliteMenu(0);
- SystemTask (); //• Handle desk accessories.
-
- ok = GetNextEvent (everyEvent, &theEvent);
- if (ok)
- switch (theEvent.what)
- {
- case mouseDown:
- HandleMouseDown(&theEvent);
- break;
-
- case keyDown:
- case autoKey:
- if ((theEvent.modifiers & cmdKey) != 0)
- {
- AdjustMenus();
- HandleMenu(MenuKey((char) (theEvent.message & charCodeMask)));
- }
- break;
-
- case updateEvt:
- BeginUpdate(shell_window);
- EndUpdate(shell_window);
- break;
-
- case activateEvt:
- InvalRect(&shell_window->portRect);
- break;
- }
- }
-
- void HandleMouseDown (EventRecord *theEvent)
- {
- WindowPtr theWindow;
- int windowCode = FindWindow (theEvent->where, &theWindow);
-
- switch (windowCode)
- {
- case inSysWindow:
- SystemClick (theEvent, theWindow);
- break;
-
- case inMenuBar:
- AdjustMenus(); //• Left over - not really needed.
- HandleMenu(MenuSelect(theEvent->where));
- break;
-
- case inContent:
- if (theWindow == shell_window)
- {
- if (theWindow != FrontWindow())
- SelectWindow(shell_window);
- else
- InvalRect(&shell_window->portRect);
- }
- break;
-
- case inGoAway:
- if (theWindow == shell_window &&
- TrackGoAway(shell_window, theEvent->where))
- HideWindow(shell_window);
- break;
- }
- }
-
- void AdjustMenus(void)
- {
- register WindowPeek wp = (WindowPeek) FrontWindow();
- short kind = wp ? wp->windowKind : 0;
- Boolean DA = kind < 0;
-
- }
-
-
- static void enable(MenuHandle menu, short item, short ok)
- {
- if (ok)
- EnableItem(menu, item);
- else
- DisableItem(menu, item);
- }
-
- void HandleMenu (long mSelect)
- {
- int menuID = HiWord(mSelect);
- int menuItem = LoWord(mSelect);
- Str255 name;
- GrafPtr savePort;
- WindowPeek frontWindow;
-
- switch (menuID)
- {
- case appleID:
- if (menuItem == 1)
- NewAbout ();
- else
- {
- GetPort (&savePort);
- GetItem (appleMenu, menuItem, name);
- OpenDeskAcc (name);
- SetPort (savePort);
- }
- break;
-
- case fileID:
- switch (menuItem)
- {
- if (frontWindow->windowKind < 0)
- CloseDeskAcc(frontWindow->windowKind);
- else
- if ((frontWindow = (WindowPeek) shell_window) != NULL)
- HideWindow(shell_window);
- break;
-
- case quitItem:
- ExitToShell();
- break;
- }
- break;
- }
- }
-
-
- void main( void)
- {
- InitMacintosh();
- SetUpMenus();
- NewAbout ();
- for (;;)
- HandleEvent();
- }
-
- void NewAbout(void)
- {
- #define mouseKey mDownMask + keyDownMask
- StringHandle str1hdl;
- Str255 str1, str2;
- WindowPtr myWindow;
- short width, height, counter, strWidth, strDepth, factor, remainder, adjust;
- long newCount;
- FontInfo txtInfo;
- Rect tempRect, tRect1;
- BitMap offScreen, tempBits;
- EventRecord theEvent;
-
- str1hdl = (StringHandle)(GetResource (0L, 0L));
- GetIndString (str1, 128, 1);
- GetIndString (str2, 128, 2);
- HLock ((Handle) str1hdl);
- myWindow = GetNewWindow (128, 0L, (WindowPtr)-1L);
- SetPort (myWindow);
- TextFont (0);
- TextSize (12);
- GetFontInfo (&txtInfo);
- width = myWindow->portRect.right - myWindow->portRect.left;
- height = myWindow->portRect.bottom - myWindow->portRect.top;
- strWidth = StringWidth ((StringPtr) &str1hdl);
- if (( StringWidth (str1) > strWidth )
- || ( StringWidth (str2) > strWidth ))
- {
- strWidth = StringWidth (str1);
- strWidth = StringWidth (str2);
- }
- strDepth = txtInfo.ascent * 2 +
- txtInfo.descent * 2 +
- txtInfo.leading + 1;
-
- //• rowbytes needs to be even.
- offScreen.rowBytes = (strWidth + 15) / 16 * 2;
- SetRect (&offScreen.bounds, 0,0,strWidth,strDepth);
- offScreen.baseAddr = NewPtrClear (offScreen.rowBytes * strDepth);
-
- tempBits = myWindow->portBits;
- SetPortBits (&offScreen);
- MoveTo ((strWidth - StringWidth (str1)) / 2, strDepth - txtInfo.ascent - 6);
- DrawString (str1);
- MoveTo ((strWidth - StringWidth (str2)) / 2, strDepth - txtInfo.descent);
- DrawString (str2);
- HUnlock ((Handle) str1hdl);
-
- SetPortBits (&tempBits);
- factor = strWidth / strDepth;
- remainder = strWidth % strDepth;
- SetRect (&tRect1, (width - remainder) / 2 - factor, height / 2 - 1,
- (width + remainder) / 2 + factor, height / 2 + 1);
- counter = 1;
- do
- {
- SystemTask ();
- CopyBits (&offScreen, &myWindow->portBits, &offScreen.bounds, &tRect1, srcCopy, 0L);
- InsetRect (&tRect1, - factor, -1);
- counter = counter + 2;
- Delay (3L, &newCount);
- } while (counter != strDepth +1) ;
-
- Delay (180L, &newCount); //• Wait 5 seconds.
-
- tempRect = offScreen.bounds;
- OffsetRect (&tempRect, (width - strWidth) / 2, (height - strDepth) / 2);
- tRect1 = offScreen.bounds;
-
- while (! EventAvail(mouseKey, &theEvent) &&
- (tRect1.right - factor * 2 > tRect1.left) )
- {
- SystemTask (); //• the clock still ticks!.
- factor = tRect1.right / strDepth;
- if ( tempRect.left > 0 )
- InsetRect (&tempRect, - factor, -2);
- else
- if ( tempRect.top > 0 )
- {
- InsetRect (&tRect1, factor, 0);
- InsetRect (&tempRect, 0, -2);
- }
- else
- InsetRect (&tRect1, factor, 2);
- CopyBits (&offScreen, &myWindow->portBits, &tRect1, &tempRect, srcCopy, 0L);
- }
- DisposPtr(offScreen.baseAddr);
- DisposeWindow (myWindow);
- }
-